const palindRome = function (left, right, s) {
  while (left >= 0 && right <= s.length - 1 && s[left] === s[right]) {
    left--
    right++
  }
  return s.substring(left + 1, right)
}

const longestPalindrome = function (s) {
  let res = ''
  for (let i = 0; i < s.length; i++) {
    let res1 = palindRome(i, i, s)
    let res2 = palindRome(i, i + 1, s)
    res = res.length > res1.length ? res : res1
    res = res.length > res2.length ? res : res2
  }
  return res
}

let s = 'cbbd'

let res = longestPalindrome(s)

console.log(res)
